#ifndef NPPPYSIDE_H
#define NPPPYSIDE_H

#ifndef SCINTILLA_H
#include "Scintilla.h"
#include "menuCmdID.h"
#endif //SCINTILLA_H

#ifndef NOTEPAD_PLUS_MSGS_H
#include "Notepad_plus_msgs.h"
#endif //NOTEPAD_PLUS_MSGS_H

#include <QtCore>
#include <QtGui>
#include <QtWidgets>
#include <string.h>
#include "NPPPySideMgrUI.h"
#include "Python.h"
#include "pyside.h"
#include "AppLib/applib_python.h"

//red npp的插件需要的结构体, 由npp提供 =======================================================>
typedef const wchar_t * (__cdecl * PFUNCGETNAME)();
struct NppData
{
    HWND _nppHandle;
    HWND _scintillaMainHandle;
    HWND _scintillaSecondHandle;
};

typedef void (__cdecl * PFUNCSETINFO)(NppData);
typedef void (__cdecl * PFUNCPLUGINCMD)();
typedef void (__cdecl * PBENOTIFIED)(SCNotification *);
typedef LRESULT (__cdecl * PMESSAGEPROC)(UINT Message, WPARAM wParam, LPARAM lParam);


struct ShortcutKey
{
    bool _isCtrl;
    bool _isAlt;
    bool _isShift;
    UCHAR _key;
};

struct FuncItem
{
    wchar_t _itemName[64];
    PFUNCPLUGINCMD _pFunc;
    int _cmdID;
    bool _init2Check;
    ShortcutKey *_pShKey;
};

typedef FuncItem * (__cdecl * PFUNCGETFUNCSARRAY)(int *);
extern "C" __declspec(dllexport) void _setInfo(NppData);
extern "C" __declspec(dllexport) const wchar_t * _getName();
extern "C" __declspec(dllexport) FuncItem * _getFuncsArray(int *);
extern "C" __declspec(dllexport) void _beNotified(SCNotification *);
extern "C" __declspec(dllexport) LRESULT _messageProc(UINT Message, WPARAM wParam, LPARAM lParam);
extern "C" __declspec(dllexport) BOOL _isUnicode();

//red npp的插件需要的结构体, 由npp提供 <=======================================================|


//blue 插件的核心逻辑模块 ====================================================================>
//核心功能类, 和植入到npp的插件进行交互
class NPPPySide : public QObject
{
public:
    static NPPPySide *instance(const NppData *nppData = nullptr);
    NPPPySide(const NppData &nppData);

    //通过不同的子菜单, 执行对面的脚本
    void CommandSwitch(unsigned int menuId);

    //释放的时候调用
    void Destroy();

    //显示npppyside的主窗口, 这个窗口是windows函创建的, 给管理窗口和子插件提供一个显示容器,
    //也就是说, 管理窗口和插件窗口, 只能同时显示一个.
    void ShowPySideWindow();

    //设置管理管理窗口成显示状态
    void SetMgrVisible(bool visible);

    //设置子插件的窗口成显示状态
    void MountWidget(QWidget *widget);

    //根据配置, 更新子插件
    void UpdateMenu();

    //打开主脚本
    void OpenMasterFile();

    //发送消息
    void SendMessageToNPP(UINT Msg, WPARAM wParam, LPARAM lParam);
    void SendMessageToScintilla(UINT Msg, WPARAM wParam, LPARAM lParam);

private:
    const NppData nppData;
    QMap<unsigned int, QPair<QString, QString> > mapMenuScript;
    NPPPythonObj *nppPythonObj;
    QWindow *window;
    QWidget *parentWidget;
    QWidget *widgetMgrUi;
    QWidget *widgetMounted;
    HWND hwnd;
};

//blue 插件的核心逻辑模块 <===================================================================|

#endif // NPPPYSIDE_H
